<?php
  class FormNewsletterManageSend extends Cible_Form{
      public function __construct($options = null)
      {
            parent::__construct($options);

            $status = $options['status'];
            $planedDate = $options['planedDate'];
            $planedTime = $options['planedTime'];
            $collectionsData = $options['filterList'];
            $statusOptions = new Zend_Form_Element_Select('NR_Status');
            $statusOptions->setLabel('Action')
            ->setAttrib('class','largeSelect');

            $statusOptions->addMultiOption('1', 'Terminé (Ne pas envoyer à nouveau)');
            $statusOptions->addMultiOption('2', "Envoyez à ceux qui ne l'ont pas reçu");
            $statusOptions->addMultiOption('3', 'Envoyez à tous les destinataires');

            $this->addElement($statusOptions);

            $send = new Zend_Form_Element_Submit('newsletter_send');
            $send->setLabel('Envoyer')
                 ->setAttrib('class','stdButton')
                 ->setOrder(2);

            $this->addActionButton($send);

            $collectionFilters = new Zend_Form_Element_Select('NR_CollectionFiltersID');
            $collectionFilters->setLabel($this->getView()->getCibleText('form_label_collection_name'))
            ->setAttrib('class','largeSelect');

//            $collectionsSelect = new NewsletterFilterCollectionsSet();
//            $select = $collectionsSelect->select()
//            ->order('NFCS_Name');
//            $collectionsData = $collectionsSelect->fetchAll($select);
            $collectionFilters->addMultiOption(0, $this->getView()->getCibleText('newsletter_send_filter_selectOne'));
            foreach($collectionsData as $key => $collection){
                $collectionFilters->addMultiOption($key, $collection);
            }
            $this->addElement($collectionFilters);

            // MailingDateScheduled
            $datePicker = new Cible_Form_Element_DatePicker('NR_MailingDate', array('jquery.params'=> array('changeYear'=>true, 'changeMonth'=> true)));

            $datePicker->setLabel($this->getView()->getCibleText('form_label_releaseDate_planned_date'))
            ->setAttrib('class','stdTextInput')
            ->setValue($planedDate)
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $this->getView()->getCibleText('validation_message_empty_field'))))
            ->addValidator('Date', true, array('messages' => array( 'dateNotYYYY-MM-DD' => $this->getView()->getCibleText('validation_message_invalid_date'),
                                                                    'dateInvalid' => $this->getView()->getCibleText('validation_message_invalid_date'),
                                                                    'dateFalseFormat' => $this->getView()->getCibleText('validation_message_invalid_date')
                                                                )));
            $this->addElement($datePicker);

            // MailingTimeScheduled
            $regexValidate = new Zend_Validate_Regex('/^([0-1]\d|2[0-3]):([0-5]\d)$/');
            $regexValidate->setMessage('Temps invalide (HH:MM)', 'regexNotMatch');

            $time = new Zend_Form_Element_Text('NR_MailingTime');
            $time->setLabel('HH:MM')
            ->setRequired(true)
            ->addFilter('StripTags')
            ->addFilter('StringTrim')
//            ->addFilter('StringToLower')
            ->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $this->getView()->getCibleText('validation_message_empty_field'))))
            ->addValidator($regexValidate)
//            ->setAttrib('class','stdTextInput')
            ->setValue($planedTime);

            $this->addElement($time);

      }
  }
?>
